#include"Head.h"
int choice;

int main()
{
	bn* bookHead, * pb;
	BN* borHead, * pB;
	UN* userHead, * pu;
	char bookId[N];
	char name[N];
	char ID[N];
	bookHead = initBook();
	userHead = initUser();
	borHead = initBor();
	while (1)
	{
		menu();
		switch (choice)
		{
		case 1:
			while (1)
			{
				menuBook();
				cin >> choice;
				switch (choice)
				{
				case 1:
					addBook(bookHead);
					bookHead = initBook();
					break;
				case 2:
					printf("\n请输入需要删除图书的编号：");
					cin >> bookId;
					bookHead = deleBook(bookHead, bookId);
					break;
				case 3:
					printf("\n请输入需要查找图书的编号：");
					cin >> bookId;
					findBook(bookHead, bookId);
					break;
				case 4:
					printf("\n请输入需要修改图书的编号：");
					cin >> bookId;
					modifyBook(bookHead, bookId);
					break;
				case 5:
					showAll(bookHead);
					break;
				case 0:
					savaBook(bookHead);
					break;
				}
				if (choice == 0)
					break;
			}
			break;
		case 2:
			while (1)
			{
				menuUser();
				cin >> choice;
				switch (choice)
				{
				case 1:
					addUser(userHead);
					userHead = initUser();
					break;
				case 2:
					printf("\n请输入需要删除用户的姓名：");
					cin >> name;
					userHead = deleUser(userHead, name);
					break;
				case 3:
					printf("\n请输入需要查找用户的姓名：");
					cin >> name;
					findUser(userHead, name);
					break;
				case 4:
					printf("\n请输入需要修改用户的姓名：");
					cin >> name;
					modifyUser(userHead, name);
					break;
				case 5:
					showall(userHead);
					break;
				case 0:
					saveUser(userHead);
					break;
				}
				if (choice == 0)
					break;
			}
			break;
		case 3:
			while (1)
			{
				menuBor();
				cin >> choice;
				switch (choice)
				{
				case 1:
					addBor(borHead);
					borHead = initBor();
					break;
				case 2:
					printf("\n请输入需要删除借阅信息的图书编号：");
					cin >> ID;
					borHead = deleBor(borHead, ID);
					break;
				case 3:
					printf("\n请输入需要查找借阅信息的图书编号：");
					cin >> ID;
					findBor(borHead, ID);
					break;
				case 4:
					printf("\n请输入需要修改借阅信息的图书编号：");
					cin >> ID;
					modifyBor(borHead, ID);
					break;
				case 5:
					ShowAll(borHead);
					break;
				case 0:
					saveBor(borHead);
					break;
				}
				if (choice == 0)
					break;
			}
			break;
		case 0:
			exit(0);
		default:
			printf("选择错误，重新选择！\n");
			break;
		}
	}
	return 0;
}

void menu()
{
	printf("*********************************\n");
	printf("***** 1. 图书信息管理       *****\n");
	printf("***** 2. 用户信息管理       *****\n");
	printf("***** 3. 借阅信息管理       *****\n");
	printf("***** 0. 退出程序           *****\n");
	printf("*********************************\n");
	cin >> choice;
}

void menuBook()
{
	printf("*********************************\n");
	printf("***** 1. 增加图书信息       *****\n");
	printf("***** 2. 删除图书信息       *****\n");
	printf("***** 3. 查找图书信息       *****\n");
	printf("***** 4. 修改图书信息       *****\n");
	printf("***** 5. 显示所有图书信息   *****\n");
	printf("***** 0. 返回上级菜单       *****\n");
	printf("*********************************\n");
}

bn* bookData(FILE* fp)
{
	bn* head = NULL, * p, * q = NULL;
	book B;
	fread(&B, sizeof(book), 1, fp);
	while (!feof(fp))
	{
		if (head == NULL)
		{
			head = (bn*)malloc(sizeof(bn));
			head->b = B;
			head->next = NULL;
			q = head;
		}
		else
		{
			p = (bn*)malloc(sizeof(bn));
			p->b = B;
			p->next = NULL;
			q->next = p;
			q = p;
		}
		fread(&B, sizeof(book), 1, fp);
	}
	return head;
}

bn* initBook()
{
	FILE* fp;
	bn* bnHead;
	if ((fp = fopen(BOOK, "r")) == NULL)
	{
		creatNewBook(BOOK);
		if ((fp = fopen(BOOK, "rb")) == NULL)
		{
			perror("init::fopen");
			exit(1);
		}
		bnHead = bookData(fp);
	}
	else
	{
		bnHead = bookData(fp);
	}
	fclose(fp);
	return bnHead;
}
void creatNewBook(const char* path)
{
	FILE* fp;
	book B;
	int i = 1;
	if ((fp = fopen(BOOK, "w")) == NULL)
	{
		perror("createNewBook::fopen");
	}
	printf("下面进行图书信息的输入（图书编号输入\'exit\'结束）：\n");
	while (1)
	{
		printf("\n请输入第%d本书的信息：\n", i++);
		printf("-------------------------------------\n");
		printf("图书编号（18个字符以内）：");
		cin >> B.ID;
		B.ID[N - 1] = '\0';
		if (strcmp(B.ID, "exit") == 0)
		{
			printf("\n输入图书信息结束！\n");
			fclose(fp);
			return;
		}
		printf("\n图书ISBN码（18个字符以内）：");
		cin >> B.ISBN;
		B.ISBN[N - 1] = '\0';
		printf("\n图书名（18个字符以内）：");
		cin >> B.BookName;
		B.BookName[N - 1] = '\0';
		printf("\n作者（18个字符以内）：");
		cin >> B.Author;
		B.Author[N - 1] = '\0';
		printf("\n出版社（18个字符以内）：");
		cin >> B.PH;
		B.PH[N - 1] = '\0';
		printf("\n图书价格：");
		cin >> B.Price;
		printf("\n图书复本数：");
		cin >> B.Num;
		printf("\n图书库存：");
		cin >> B.Sum;
		printf("-------------------------------------\n");
		fwrite(&B, sizeof(book), 1, fp);
	}
}

void addBook(bn* head)
{
	bn* p = head;
	book B;
	if (head == NULL)
	{
		printf("当前没有图书!\n");
		creatNewBook(BOOK);
		return;
	}
	while (p->next != NULL)
	{
		p = p->next;
	}
	int i = 0;
	char cho = 'Y';
	while (cho=='Y')
	{
		printf("\n请输入图书信息：");
		printf("-------------------------------------\n");
		printf("图书编号（18个字符以内）：");
		cin >> B.ID;
		B.ID[N - 1] = '\0';
		printf("\n图书ISBN码（18个字符以内）：");
		cin >> B.ISBN;
		B.ISBN[N - 1] = '\0';
		printf("\n图书名（18个字符以内）：");
		cin >> B.BookName;
		B.BookName[N - 1] = '\0';
		printf("\n作者（18个字符以内）：");
		cin >> B.Author;
		B.Author[N - 1] = '\0';
		printf("\n出版社（18个字符以内）：");
		cin >> B.PH;
		B.PH[N - 1] = '\0';
		printf("\n图书价格：");
		cin >> B.Price;
		printf("\n图书复本数：");
		cin >> B.Num;
		printf("\n图书库存：");
		cin >> B.Sum;
		printf("\n-------------------------------------\n");
		p->next = (bn*)malloc(sizeof(bn));
		p = p->next;
		p->b = B;
		p->next = NULL;
		i++;
		printf("是否继续增加图书(y/n)?\n");
		cin >> cho;
		if (cho == 'y')
			cho = cho - 32;
	}
	printf("\n增加成功，共增加了%d本书。\n", i);
	savaBook(head);
	return;
}
bn* deleBook(bn* head, char* bookid)
{
	bn* p = head, * q = head;
	if (p == NULL)
	{
		printf("暂无图书\n");
		return head;
	}
	if (strcmp(p->b.ID, bookid) == 0)
	{
		head = head->next;
		free(p);
		printf("删除成功\n");
		return head;
	}
	else
	{
		while (p->next != NULL)
		{
			if (strcmp(p->next->b.ID, bookid) == 0)
			{
				bn* t = p->next;
				p->next = p->next->next;
				free(t);
				printf("删除成功\n");
				return head;
			}
			p = p->next;
		}
		printf("没有此书！\n");
		return head;
	}
}
void findBook(bn* head, char* bookid)
{
	bn* p = head;
	while (p != NULL)
	{
		if (strcmp(p->b.ID, bookid) == 0)
		{
			printf("图书编号： %-18s\n", p->b.ID);
			printf("ISBN码：   %-18s\n", p->b.ISBN);
			printf("书名：     %-18s\n", p->b.BookName);
			printf("作者：     %-18s\n", p->b.Author);
			printf("出版社：   %-18s\n", p->b.PH);
			printf("价格：     %-5.2f\n", p->b.Price);
			printf("复本数：   %-7d\n", p->b.Num);
			printf("库存数：   %-7d\n\n", p->b.Sum);
			return;
		}
		p = p->next;
	}
	if (p == NULL)
	{
		printf("输入书籍编号错误（或者没有这本书）\n");
	}
}
void modifyMenu()
{
	while (1)
	{
		printf("*********************************\n");
		printf("***** 1. 修改图书编号       *****\n");
		printf("***** 2. 修改ISBN           *****\n");
		printf("***** 3. 修改价格           *****\n");
		printf("***** 4. 修改复本数         *****\n");
		printf("***** 5. 修改库存数         *****\n");
		printf("*********************************\n");
		cin >> choice;
		cout << endl;
		if (choice < 0 || choice > 5)
		{
			printf("请选择正确的操作！\n");
			system("pause");
		}
		else
			return;
	}
}
void modifyBook(bn* head, char* bookid)
{
	bn* p = head;
	while (p != NULL)
	{
		if (strcmp(p->b.ID, bookid) == 0)
			break;
		p = p->next;
	}
	modifyMenu();
	switch (choice)
	{
	case 1:
		printf("\n原图书的编号是：%-18s\n", p->b.ID);
		printf("请输入新的编号：");
		cin >> p->b.ID;
		p->b.ID[N - 1] = '\0';
		break;
	case 2:
		printf("\n原图书的ISBN是：%-18s\n", p->b.ISBN);
		printf("请输入新的ISBN：");
		cin >> p->b.ISBN;
		p->b.ISBN[N - 1] = '\0';
		break;
	case 3:
		printf("\n原图书的价格是：%-.2f\n", p->b.Price);
		printf("请输入新的价格：");
		cin >> p->b.Price;
		break;
	case 4:
		printf("\n原图书的复本数是：%d\n", p->b.Num);
		printf("请输入新的复本数：");
		cin >> p->b.Num;
		break;
	case 5:
		printf("\n原图书的库存数是：%d\n", p->b.Sum);
		printf("请输入新的库存数：");
		cin >> p->b.Sum;
		break;
	}
	printf("\n修改完成！\n");
	system("pause");
}
void showAll(bn* head)
{
	bn* p = head;
	printf("-----------------------------------------\n");
	while (p != NULL)
	{
		printf("图书编号： %-18s\n", p->b.ID);
		printf("ISBN码：   %-18s\n", p->b.ISBN);
		printf("书名：     %-18s\n", p->b.BookName);
		printf("作者：     %-18s\n", p->b.Author);
		printf("出版社：   %-18s\n", p->b.PH);
		printf("价格：     %-5.2f\n", p->b.Price);
		printf("复本数：   %-7d\n", p->b.Num);
		printf("库存数：   %-7d\n\n", p->b.Sum);
		p = p->next;
	}
	printf("-----------------------------------------\n");
}

void savaBook(bn* head)
{
	FILE* fp;
	bn* p = head;
	if ((fp = fopen(BOOK, "w")) == NULL)
	{
		perror("savaBook::fopen");
		return;
	}
	while (p != NULL)
	{
		fwrite(&p->b, sizeof(book), 1, fp);
		p = p->next;
	}
	fclose(fp);
	printf("保存成功！\n");
	system("pause");
}

void creatNewUser(const char* path)
{
	FILE* fp;
	user B;
	int i = 1;
	if ((fp = fopen(USER, "w")) == NULL)
	{
		perror("createNewBook::fopen");
	}
	printf("下面进行用户信息的输入（借书证号输入\'exit\'结束）：\n");
	while (1)
	{
		printf("\n请输入第%d个用户的信息：\n", i++);
		printf("-------------------------------------\n");
		printf("借书证号（15个字符以内）：");
		cin >> B.ID;
		B.ID[PEO - 1] = '\0';
		if (strcmp(B.ID, "exit") == 0)
		{
			printf("\n输入用户信息结束！\n");
			fclose(fp);
			return;
		}
		printf("\n用户姓名（15个字符以内）：");
		cin >> B.Name;
		B.Name[PEO - 1] = '\0';
		printf("\n性别（5个字符以内）：");
		cin >> B.Sex;
		B.Sex[SEX - 1] = '\0';
		printf("\n出生日期（15个字符以内）：");
		cin >> B.Time;
		B.Time[PEO - 1] = '\0';
		printf("\n专业（15个字符以内）：");
		cin >> B.SP;
		B.SP[PEO - 1] = '\0';
		printf("-------------------------------------\n");
		fwrite(&B, sizeof(user), 1, fp);
	}
}
void menuUser()
{
	printf("*********************************\n");
	printf("***** 1. 增加用户信息       *****\n");
	printf("***** 2. 删除用户信息       *****\n");
	printf("***** 3. 查找用户信息       *****\n");
	printf("***** 4. 修改用户信息       *****\n");
	printf("***** 5. 显示所有用户信息   *****\n");
	printf("***** 0. 返回上级菜单       *****\n");
	printf("*********************************\n");
}
UN* userData(FILE* fp)
{
	UN* head = NULL, * p, * q = NULL;
	user B;
	fread(&B, sizeof(user), 1, fp);
	while (!feof(fp))
	{
		if (head == NULL)
		{
			head = (UN*)malloc(sizeof(UN));
			head->us = B;
			head->next = NULL;
			q = head;
		}
		else
		{
			p = (UN*)malloc(sizeof(UN));
			p->us = B;
			p->next = NULL;
			q->next = p;
			q = p;
		}
		fread(&B, sizeof(user), 1, fp);
	}
	return head;
}
UN* initUser()
{
	FILE* fp;
	UN* unHead;
	if ((fp = fopen(USER, "r")) == NULL)
	{
		creatNewUser(USER);
		if ((fp = fopen(USER, "rb")) == NULL)
		{
			perror("initUser::fopen");
			exit(1);
		}
		unHead = userData(fp);
	}
	else
	{
		unHead = userData(fp);
	}
	fclose(fp);
	return unHead;
}
void showall(UN* head)
{
	UN* p = head;
	printf("-----------------------------------------\n");
	while (p != NULL)
	{
		printf("借书证号： %-15s\n", p->us.ID);
		printf("姓名：     %-15s\n", p->us.Name);
		printf("性别：     %-15s\n", p->us.Sex);
		printf("出生日期   %-15s\n", p->us.Time);
		printf("专业：     %-15s\n\n", p->us.SP);
		p = p->next;
	}
	printf("-----------------------------------------\n");
}
void addUser(UN* head)
{
	UN* p = head;
	user B;
	if (head == NULL)
	{
		printf("当前没有用户!\n");
		creatNewUser(USER);
		return;
	}
	while (p->next != NULL)
	{
		p = p->next;
	}
	int i = 0;
	char cho = 'Y';
	while (cho == 'Y')
	{
		printf("\n请输入图书信息：");
		printf("-------------------------------------\n");
		printf("借书证号（15个字符以内）：");
		cin >> B.ID;
		B.ID[PEO - 1] = '\0';
		printf("\n用户姓名（15个字符以内）：");
		cin >> B.Name;
		B.Name[PEO - 1] = '\0';
		printf("\n性别（5个字符以内）：");
		cin >> B.Sex;
		B.Sex[SEX - 1] = '\0';
		printf("\n出生日期（15个字符以内）：");
		cin >> B.Time;
		B.Time[PEO - 1] = '\0';
		printf("\n专业（15个字符以内）：");
		cin >> B.SP;
		B.SP[PEO - 1] = '\0';
		printf("\n-------------------------------------\n");
		p->next = (UN*)malloc(sizeof(UN));
		p = p->next;
		p->us = B;
		p->next = NULL;
		i++;
		printf("是否继续增加用户(y/n)?\n");
		cin >> cho;
		if (cho == 'y')
			cho = cho - 32;
	}
	printf("\n增加成功，共增加了%d个用户。\n", i);
	saveUser(head);
	return;
}
UN* deleUser(UN* head, char* name)
{
	UN* p = head, * q = head;
	if (p == NULL)
	{
		printf("暂无图书\n");
		return head;
	}
	if (strcmp(p->us.Name, name) == 0)
	{
		head = head->next;
		free(p);
		printf("删除成功\n");
		return head;
	}
	else
	{
		while (p->next != NULL)
		{
			if (strcmp(p->next->us.Name, name) == 0)
			{
				UN* t = p->next;
				p->next = p->next->next;
				free(t);
				printf("删除成功\n");
				return head;
			}
			p = p->next;
		}
		printf("没有此人！\n");
		return head;
	}
}
void findUser(UN* head, char* name)
{
	UN* p = head;
	while (p != NULL)
	{
		if (strcmp(p->us.Name, name) == 0)
		{
			printf("借书证号： %-15s\n", p->us.ID);
			printf("姓名：     %-15s\n", p->us.Name);
			printf("性别：     %-15s\n", p->us.Sex);
			printf("出生日期   %-15s\n", p->us.Time);
			printf("专业：     %-15s\n", p->us.SP);
			return;
		}
		p = p->next;
	}
	if (p == NULL)
	{
		printf("输入书籍编号错误（或者没有这本书）\n");
	}
}
void modifymenu()
{
	while (1)
	{
		printf("*********************************\n");
		printf("***** 1. 修改用户姓名       *****\n");
		printf("***** 2. 修改用户性别       *****\n");
		printf("***** 3. 修改用户出生日期   *****\n");
		printf("***** 4. 修改用户专业       *****\n");
		printf("*********************************\n");
		cin >> choice;
		cout << endl;
		if (choice < 0 || choice > 4)
		{
			printf("请选择正确的操作！\n");
			system("pause");
		}
		else
			return;
	}
}
void modifyUser(UN* head, char* name)
{
	UN* p = head;
	while (p != NULL)
	{
		if (strcmp(p->us.Name, name) == 0)
			break;
		p = p->next;
	}
	modifymenu();
	switch (choice)
	{
	case 1:
		printf("\n原用户的姓名是：%-15s\n", p->us.Name);
		printf("请输入新的姓名：");
		cin >> p->us.Name;
		p->us.Name[PEO - 1] = '\0';
		break;
	case 2:
		printf("\n原用户的性别是：%-15s\n", p->us.Sex);
		printf("请输入新的性别：");
		cin >> p->us.Sex;
		p->us.Sex[SEX - 1] = '\0';
		break;
	case 3:
		printf("\n原用户的出生日期是：%-15s\n", p->us.Time);
		printf("请输入新的出生日期：");
		cin >> p->us.Time;
		break;
	case 4:
		printf("\n原用户的专业是：%-15s\n", p->us.SP);
		printf("请输入新的专业：");
		cin >> p->us.SP;
		break;
	}
	printf("\n修改完成！\n");
	system("pause");
}
void saveUser(UN* head)
{
	FILE* fp;
	UN* p = head;
	if ((fp = fopen(USER, "w")) == NULL)
	{
		perror("savaUser::fopen");
		return;
	}
	while (p != NULL)
	{
		fwrite(&p->us, sizeof(user), 1, fp);
		p = p->next;
	}
	fclose(fp);
	printf("保存成功！\n");
	system("pause");
}

void menuBor()
{
	printf("*********************************\n");
	printf("***** 1. 增加借阅信息       *****\n");
	printf("***** 2. 删除借阅信息       *****\n");
	printf("***** 3. 查找借阅信息       *****\n");
	printf("***** 4. 修改借阅信息       *****\n");
	printf("***** 5. 显示所有借阅信息   *****\n");
	printf("***** 0. 返回上级菜单       *****\n");
	printf("*********************************\n");
}
void creatNewBor(const char* path)
{
	FILE* fp;
	Borr B;
	int i = 1;
	if ((fp = fopen(BORR, "w")) == NULL)
	{
		perror("createNewBor::fopen");
	}
	printf("下面进行借阅信息的输入（图书编号输入\'exit\'结束）：\n");
	while (1)
	{
		printf("\n请输入第%d个借阅的信息：\n", i++);
		printf("-------------------------------------\n");
		printf("图书编号（15个字符以内）：");
		cin >> B.ID;
		B.ID[N - 1] = '\0';
		if (strcmp(B.ID, "exit") == 0)
		{
			printf("\n输入借阅信息结束！\n");
			fclose(fp);
			return;
		}
		printf("\n借书证号（15个字符以内）：");
		cin >> B.CardID;
		B.CardID[N - 1] = '\0';
		printf("\nISBN（18个字符以内）：");
		cin >> B.ISBN;
		B.ISBN[SEX - 1] = '\0';
		printf("\n借书日期（18个字符以内）：");
		cin >> B.Time;
		B.Time[N - 1] = '\0';
		printf("-------------------------------------\n");
		fwrite(&B, sizeof(Borr), 1, fp);
	}
}

BN* BorData(FILE* fp)
{
	BN* head = NULL, * p, * q = NULL;
	Borr B;
	fread(&B, sizeof(Borr), 1, fp);
	while (!feof(fp))
	{
		if (head == NULL)
		{
			head = (BN*)malloc(sizeof(BN));
			head->bor = B;
			head->next = NULL;
			q = head;
		}
		else
		{
			p = (BN*)malloc(sizeof(BN));
			p->bor = B;
			p->next = NULL;
			q->next = p;
			q = p;
		}
		fread(&B, sizeof(Borr), 1, fp);
	}
	return head;
}
BN* initBor()
{
	FILE* fp;
	BN* unHead;
	if ((fp = fopen(BORR, "r")) == NULL)
	{
		creatNewBor(BORR);
		if ((fp = fopen(BORR, "rb")) == NULL)
		{
			perror("initBor::fopen");
			exit(1);
		}
		unHead = BorData(fp);
	}
	else
	{
		unHead = BorData(fp);
	}
	fclose(fp);
	return unHead;
}
void ShowAll(BN* head)
{
	BN* p = head;
	printf("-----------------------------------------\n");
	while (p != NULL)
	{
		printf("图书编号： %-15s\n", p->bor.ID);
		printf("借书证号： %-15s\n", p->bor.CardID);
		printf("ISBN：     %-15s\n", p->bor.ISBN);
		printf("借书日期   %-15s\n\n", p->bor.Time);
		p = p->next;
	}
	printf("-----------------------------------------\n");
}
void addBor(BN* head)
{
	BN* p = head;
	Borr B;
	if (head == NULL)
	{
		printf("当前没有借阅信息!\n");
		creatNewBor(BORR);
		return;
	}
	while (p->next != NULL)
	{
		p = p->next;
	}
	int i = 0;
	char cho = 'Y';
	while (cho == 'Y')
	{
		printf("\n请输入借阅信息：");
		printf("-------------------------------------\n");
		printf("图书编号（15个字符以内）：");
		cin >> B.ID;
		B.ID[N - 1] = '\0';
		printf("\n借书证号（15个字符以内）：");
		cin >> B.CardID;
		B.CardID[N - 1] = '\0';
		printf("\nISBN（18个字符以内）：");
		cin >> B.ISBN;
		B.ISBN[N - 1] = '\0';
		printf("\n借书日期（18个字符以内）：");
		cin >> B.Time;
		B.Time[N - 1] = '\0';
		printf("-------------------------------------\n");
		p->next = (BN*)malloc(sizeof(BN));
		p = p->next;
		p->bor = B;
		p->next = NULL;
		i++;
		printf("是否继续增加借阅信息(y/n)?\n");
		cin >> cho;
		if (cho == 'y')
			cho = cho - 32;
	}
	printf("\n增加成功，共增加了%d个借阅信息。\n", i);
	saveBor(head);
	return;
}
BN* deleBor(BN* head, char* id)
{
	BN* p = head, * q = head;
	if (p == NULL)
	{
		printf("暂无借阅信息\n");
		return head;
	}
	if (strcmp(p->bor.ID, id) == 0)
	{
		head = head->next;
		free(p);
		printf("删除成功\n");
		return head;
	}
	else
	{
		while (p->next != NULL)
		{
			if (strcmp(p->next->bor.ID, id) == 0)
			{
				BN* t = p->next;
				p->next = p->next->next;
				free(t);
				printf("删除成功\n");
				return head;
			}
			p = p->next;
		}
		printf("没有此借阅信息！\n");
		return head;
	}
}
void findBor(BN* head, char* id)
{
	BN* p = head;
	while (p != NULL)
	{
		if (strcmp(p->bor.ID, id) == 0)
		{
			printf("图书编号： %-15s\n", p->bor.ID);
			printf("借书证号： %-15s\n", p->bor.CardID);
			printf("ISBN：     %-15s\n", p->bor.ISBN);
			printf("借书日期   %-15s\n\n", p->bor.Time);
			return;
		}
		p = p->next;
	}
	if (p == NULL)
	{
		printf("输入书籍编号错误（或者没有这本书）\n");
	}
}
void ModifyMenu()
{
	while (1)
	{
		printf("*********************************\n");
		printf("***** 1. 修改图书编号       *****\n");
		printf("***** 2. 修改借书证号       *****\n");
		printf("***** 3. 修改ISBN           *****\n");
		printf("***** 4. 修改借书时间       *****\n");
		printf("*********************************\n");
		cin >> choice;
		cout << endl;
		if (choice < 0 || choice > 4)
		{
			printf("请选择正确的操作！\n");
			system("pause");
		}
		else
			return;
	}
}
void modifyBor(BN* head, char* id)
{
	BN* p = head;
	while (p != NULL)
	{
		if (strcmp(p->bor.ID, id) == 0)
			break;
		p = p->next;
	}
	ModifyMenu();
	switch (choice)
	{
	case 1:
		printf("\n原图书编号是：%-15s\n", p->bor.ID);
		printf("请输入新的编号：");
		cin >> p->bor.ID;
		p->bor.ID[N - 1] = '\0';
		break;
	case 2:
		printf("\n原借书证号是：%-15s\n", p->bor.CardID);
		printf("请输入新的借书证号：");
		cin >> p->bor.CardID;
		p->bor.CardID[N - 1] = '\0';
		break;
	case 3:
		printf("\n原图书ISBN是：%-15s\n", p->bor.ISBN);
		printf("请输入新的ISBN：");
		cin >> p->bor.ISBN;
		p->bor.ISBN[N - 1] = '\0';
		break;
	case 4:
		printf("\n原借书时间是：%-15s\n", p->bor.Time);
		printf("请输入新的借书时间：");
		cin >> p->bor.Time;
		p->bor.Time[N - 1] = '\0';
		break;
	}
	printf("\n修改完成！\n");
	system("pause");
}
void saveBor(BN* head)
{
	FILE* fp;
	BN* p = head;
	if ((fp = fopen(BORR, "w")) == NULL)
	{
		perror("savaBor::fopen");
		return;
	}
	while (p != NULL)
	{
		fwrite(&p->bor, sizeof(Borr), 1, fp);
		p = p->next;
	}
	fclose(fp);
	printf("保存成功！\n");
	system("pause");
}